import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.math.BigInteger;
import java.nio.ByteBuffer;
import java.security.MessageDigest;

public class ByteBufferText {
    public static void main(String[] args) {
//        String str = "1111111232131321";
//        ByteBuffer buffer = ByteBuffer.allocate(200);
//        buffer.put(str.getBytes());
////        buffer.flip();
////        buffer.clear();
//        buffer.putInt(5);
//        byte[] array = buffer.array();
//        String str1 = new String(array);
//        System.out.println(str1);

        String file1Path = "D:\\1111.docx";
        String file2Path = "D:\\1111 - 副本.docx";
//        File file1 = new File(file1Path);
//        File file2 = new File(file2Path);

        String s1 = md5HashCode(file1Path);
        String s2 = md5HashCode(file2Path);

        if (s1.equals(s2)) {
            System.out.println(s1);
            System.out.println(s2);
            System.out.println(true);
        }else {
            System.out.println(s1);
            System.out.println(s2);
            System.out.println(false);
        }
    }

    /**
     * 获取文件md5值
     */
    private static String md5HashCode(String filePath) {
        try {
            InputStream fis = new FileInputStream(filePath);
            MessageDigest md = MessageDigest.getInstance("MD5");
            byte[] buffer = new byte[1024];
            int length = -1;
            while ((length = fis.read(buffer, 0, 1024)) != -1) {
                md.update(buffer, 0, length);
            }
            fis.close();
            //转换并返回包含16个元素字节数组,返回数值范围为-128到127
            byte[] md5Bytes = md.digest();
            BigInteger bigInt = new BigInteger(1, md5Bytes);
            return bigInt.toString(16);
        } catch (Exception e) {
            e.printStackTrace();
            return "";
        }
    }

}
